package com.example.design.personal.observer;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;

/**
 * 被观察者
 */
public class Subject {

    private List<Observer> observerList = new ArrayList<>();

    private Message message;

    public Message getMessage() {
        return message;
    }

    public void setMessage(Message message) {
        this.message = message;
        this.notifyAlllObserver();
    }

    public List<Observer> getObserverList() {
        return observerList;
    }

    public void addAttach(Observer observer){

        observerList.add(observer);
    }

    public void setObserverList(List<Observer> observerList) {
        this.observerList = observerList;
    }


    public void notifyAlllObserver(){
        for(Observer observer:observerList){
            observer.update(message);
        }
    }
}
